package com.avic.rong.activity.IncreaseTQ;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.api.increase_tp.IncreasetpApi;
import com.avic.rong.questionOrAnswer.StringUtil;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.SharedPreferencesUtil;
import com.avic.rong.utils.StringUtils;
import com.avic.rong.utils.ToastTools;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;

import butterknife.BindView;

//增票资质-添加增票资质
public class Increase_TpActivity extends BaseActivity {

    @BindView(R.id.et_companyName)
    EditText et_companyName;
    @BindView(R.id.et_identificationNumber)
    EditText et_identificationNumber;
    @BindView(R.id.et_regAddressr)
    EditText et_regAddressr;
    @BindView(R.id.et_regMobile)
    EditText et_regMobile;
    @BindView(R.id.et_bank)
    EditText et_bank;
    @BindView(R.id.et_blankNo)
    EditText et_blankNo;
    @BindView(R.id.btn_commit)
    Button btn_commit;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_increase__tp;
    }

    @Override
    protected void initView() {
        tvTitle.setText("添加增票资质");
        ivRight.setBackgroundResource(R.mipmap.slh);
    }

    @Override
    protected void addListener() {

        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addTp();
            }
        });
    }
    private void addTp() {
        String companyName = et_companyName.getText().toString().trim();
        String identificationNumber = et_identificationNumber.getText().toString().trim();
        String regAddressr = et_regAddressr.getText().toString().trim();
        String regMobile = et_regMobile.getText().toString().trim();
        String bank = et_bank.getText().toString().trim();
        String blankNo = et_blankNo.getText().toString().trim();

        String loginToken = SharedPreferencesUtil.getLoginToken();



        if (StringUtils.isEmpty(companyName)||StringUtils.isEmpty(regAddressr)||StringUtils.isEmpty(regMobile)||
                StringUtils.isEmpty(bank)||StringUtils.isEmpty(blankNo)||StringUtils.isEmpty(loginToken)) {
            ToastTools.showPublicToast("内容不能为空");
        }else {
            /*if(StringUtil.isEmpty(identificationNumber)){
                IncreasetpApi increasetpApi = new IncreasetpApi(this, increaseTpListener);
                increasetpApi.setArgument(loginToken, companyName, identificationNumber, regAddressr, regMobile, bank, blankNo);
                HttpManager.getInstance().doHttpDeal(increasetpApi);
            }else {
                if (!identificationNumber.matches("/^[0-9A-Z]*$/g")) {
                    ToastTools.showPublicToast("纳税人识别号内容不正确");
                }else {
                    IncreasetpApi increasetpApi = new IncreasetpApi(this, increaseTpListener);
                    increasetpApi.setArgument(loginToken, companyName, identificationNumber, regAddressr, regMobile, bank, blankNo);
                    HttpManager.getInstance().doHttpDeal(increasetpApi);
                }
            }*/
            IncreasetpApi increasetpApi = new IncreasetpApi(this, increaseTpListener);
            increasetpApi.setArgument(loginToken, companyName, identificationNumber, regAddressr, regMobile, bank, blankNo);
            HttpManager.getInstance().doHttpDeal(increasetpApi);
        }
    }
    HttpOnNextListener<BaseResultEntity> increaseTpListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity baseResultEntity) {
            if (baseResultEntity.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)){
                //回到账号设置界面
                finish();
            }else {
                ToastTools.showPublicToast(baseResultEntity.getMsg());
            }
        }
    };

    public static Intent queryIntent(Context context){
        Intent intent = new Intent(context, Increase_TpActivity.class);
        return intent;
    }
}
